package com.woniu.car.controller;


import com.mysql.jdbc.StringUtils;
import com.woniu.car.client.PlatformClient;
import com.woniu.car.client.UserClient;
import com.woniu.car.common.JWTUtil;
import com.woniu.car.common.ResponseEntity;
import com.woniu.car.exception.ParamException;

import com.woniu.car.param.GoodsOrderParam;
import com.woniu.car.service.TOrderGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chestnuts
 * @since 2021-06-21
 */
@Slf4j
@Api(tags = "商品订单模块")
@RestController
@RequestMapping("/tOrderGoods")
public class TOrderGoodsController {

    @Autowired
    private TOrderGoodsService orderGoodsService;

    @Resource
    private PlatformClient platformClient;

    @Resource
    private UserClient userClient;

    @ApiOperation("商品下单")
    @PostMapping("/placeAnGoodsOrder")
    public ResponseEntity placeAnGoodsOrder(@RequestBody GoodsOrderParam goodsOrderParams, HttpServletRequest request) throws Exception {
        //商品下单 生成一个带有 商品总价 用户id 订单状态 支付状态  创建时间 订单总价 的订单
        //订单明细 商品id 商品数量 商品单价
        //优惠券id



//
        String token = request.getHeader("token");
        if (token==null){
            throw new ParamException("当前未登录，请登录后操作");
        }

        String id1 = JWTUtil.getId(token);
        int userId = Integer.parseInt(id1);
        ResponseEntity userInfo = userClient.selectUserInfoByUserId(userId);
        ResponseEntity responseEntity = orderGoodsService.placeGoodsOrder(goodsOrderParams, userId);

        return responseEntity;

    }

    @ApiOperation("更新订单状态")
    @PutMapping("/putGoodsOrderStatus")
    public ResponseEntity putGoodsOrderStatus(@RequestParam(value = "orderId") Integer orderId) throws ParamException {
        //商品下单 生成一个带有 商品总价 用户id 订单状态 支付状态  创建时间 订单总价 的订单
        //订单明细 商品id 商品数量 商品单价
        //优惠券id

        int id=6;
        ResponseEntity responseEntity = orderGoodsService.putGoodsOrderStatus(orderId);

        return responseEntity;

    }

    @ApiOperation("更新订单状态")
    @PutMapping("/overOrderStatus")
    public ResponseEntity overOrderStatus(@RequestParam(value = "orderId") Integer orderId) throws ParamException {
        //商品下单 生成一个带有 商品总价 用户id 订单状态 支付状态  创建时间 订单总价 的订单
        //订单明细 商品id 商品数量 商品单价
        //优惠券id

        int id=6;
        ResponseEntity responseEntity = orderGoodsService.OverOrderStatus(orderId);

        return responseEntity;

    }



//    @PostMapping("/insert")
//    @ApiOperation("新增评论")
//    public ResponseEntity insertComment( @Valid GoodsOrderParam goodsOrderParam) throws ParamException {
//
//        GoodsCommentInsertDto goodsCommentInsertDto = tServiceCommentService.insertComment(goodsCommentInsterParam);
//
//        return null;
//    }




}

